﻿//------------------------------------------------------------------------------
// System Name:    Customer Service Platform
// Component:      CIS Overseas PreferenceLevel 
// Created By:     Samara Jiang (samaraj@wicresoft.com)
// Created Date:   2011-2-20
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASBCC.Business;
using ASBCC.Business.CIS;
using ASBCC.Database.EntityFramework;

namespace ASB.CC.Web.CIS2.Overseas.Admin
{
    /// <summary>
    /// CIS Overseas PreferenceValueManagement
    /// </summary>
    public partial class PreferenceValue : EntityPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override EntityDataSource EntitySource
        {
            get { return this.edsValue; }
        }

        protected override TextBox EntitySearchTxt
        {
            get { return this.SearchText; }
        }

        protected override Button EntityAddBtn
        {
            get { return this.BtnAdd; }
        }

        protected override Button EntitySearchBtn
        {
            get { return this.Searchbtn; }
        }

        protected override Button EntityClearBtn
        {
            get { return this.Cleanbtn; }
        }

        protected override GridView EntityGrid
        {
            get { return this.gvValue; }
        }

        protected override DetailsView EntityDetails
        {
            get { return this.dvValue; }
        }



        protected override void OnEntityDisabling(int entityKey)
        {
            IPrincipal user = (IPrincipal)(Context.User);
            PreferenceManagementHelper.SetValueDisabled(entityKey);
            GlobalHelper.LogOperation(user.Identity.Name, SystemModule.CIO, "PreferenceValue disabled. id=" + entityKey + "; name=" + PreferenceManagementHelper.getValueName(entityKey));
        }

        protected override string GetEntityWhereExpression(string keyword)
        {
            return "(it.Name like N'%" + keyword + "%'"
                 + " or it.Description like N'%" + keyword + "%')";
        }

        protected override void OnEntityInserting(EntityDataSourceChangingEventArgs e)
        {

        }

        protected override void OnEntityUpdating(EntityDataSourceChangingEventArgs e)
        {

        }



        protected void edsValue_Inserted(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var preferenceValue = e.Entity as PreferencesValue;
            IPrincipal user = (IPrincipal)(Context.User);
            GlobalHelper.LogOperation(user.Identity.Name, SystemModule.CIO, "PreferenceValue inserted. id=" + preferenceValue.ValueID + "; name=" + preferenceValue.Name + "; description=" + preferenceValue.Description);
        }

        protected void edsValue_Updated(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var preferenceValue = e.Entity as PreferencesValue;
            IPrincipal user = (IPrincipal)(Context.User);
            GlobalHelper.LogOperation(user.Identity.Name, SystemModule.CIO, "PreferenceValue updated. id=" + preferenceValue.ValueID + "; name=" + preferenceValue.Name + "; description=" + preferenceValue.Description);
        }
        protected string GetTabClass(int flag)
        {
            string t = Request.QueryString["type"];
            if (String.IsNullOrEmpty(t))
            {
                if (flag == 1)
                {
                    return "tab_active";
                }
                else
                {
                    return "tab_link";
                }
            }
            else if (t == "Level")
            {
                if (flag == 2)
                {
                    return "tab_active";
                }
                else
                {
                    return "tab_link";
                }
            }
            else
            {
                if (flag == 3)
                {
                    return "tab_active";
                }
                else
                {
                    return "tab_link";
                }
            }
        }

    }
}
